<link rel="stylesheet" href="/styles/flexigrid.css" />
<link rel="stylesheet" href="/styles/thickbox.css" />
<script type="text/javascript" src="/scripts/jquery-1.3.2.js"></script>
<script type="text/javascript" src="/scripts/flexigrid.js"></script>
<script type="text/javascript" src="/scripts/thickbox.js"></script>

<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
 
	$("#flex1").flexigrid
			(
			{
			url: '/admin-mvc/news/manage/list-news',
			dataType: 'json',
			colModel : [
				{display: 'Id', name : 'id', width : 20, sortable : true, align: 'left'},
				{display: 'Title', name : 'news_title', width : 200, sortable : true, align: 'left'},
				{display: 'Description', name : 'news_desc', width : 150, sortable : true, align: 'left'},
				{display: 'Created Date', name : 'created_date', width : 150, sortable : true, align: 'left'},
				{display: 'Modified Date', name : 'modified_date', width : 150, sortable : true, align: 'left'},
				{display: 'Status', name : 'status', width : 100, sortable : true, align: 'left'}
				
				],
			buttons : [
				{name: 'Add', bclass: 'add', onpress : gridAction},
				{separator: true},
				{name: 'Edit', bclass: 'add', onpress :gridAction},
				{separator: true},
				{name: 'Activate', bclass: 'add', onpress :gridAction},
				{separator: true},
				{name: 'De-Activate', bclass: 'delete', onpress :gridAction},
				{separator: true},
				{name: 'Delete', bclass: 'delete', onpress :gridAction},
				
				],
			searchitems : [
				{display: 'Title', name : 'news_title', isdefault:false}
				],
			sortname: "id",
			sortorder: "desc",
			usepager: true,
			title: 'Manage News',
			useRp: true,
			rp: 10,
			showTableToggleBtn: false,
			width: 970,
			height: 320
			}
			);   
	
});
function sortAlpha(com)
			{ 
			jQuery('#flex1').flexOptions({newp:1, params:[{name:'letter_pressed', value: com},{name:'qtype',value:$('select[name=qtype]').val()}]});
			jQuery("#flex1").flexReload(); 
			}
function gridAction(com,grid)
{
	 if (com=='Activate'){
		if($('.trSelected',grid).length>0){
	   		if(confirm('Activate ' + $('.trSelected',grid).length + ' News?')){
            	var items = $('.trSelected',grid);
            	var itemlist ='';
        		for(i=0;i<items.length;i++){
					itemlist+= items[i].id.substr(3)+",";
				}
				$.ajax({
					type: "POST",
				   	dataType: "json",
				   	url: "/admin-mvc/news/manage/activate",
				   	data: "items="+itemlist,
				   	success: function(data){
				   		alert(data.total + " News Activated");
				   		$("#flex1").flexReload();
			   	    }
				});
			}
		} else {
			alert('Please select at least 1 News');
		} 
	} else if (com=='De-Activate'){
		if($('.trSelected',grid).length>0){
	   		if(confirm('De-Activate ' + $('.trSelected',grid).length + ' News?')){
            	var items = $('.trSelected',grid);
            	var itemlist ='';
        		for(i=0;i<items.length;i++){
					itemlist+= items[i].id.substr(3)+",";
				}
				$.ajax({
					type: "POST",
				   	dataType: "json",
				   	url: "/admin-mvc/news/manage/de-activate",
				   	data: "items="+itemlist,
				   	success: function(data){
				   		alert(data.total + " News De-Activated");
				   		$("#flex1").flexReload();
			   	    }
				});
			}
		} else {
			alert('Please select at least 1 News');
		} 
	} else if (com=='Delete'){
		if($('.trSelected',grid).length>0){
	   		if(confirm('Delete ' + $('.trSelected',grid).length + ' News?')){
            	var items = $('.trSelected',grid);
            	var itemlist ='';
        		for(i=0;i<items.length;i++){
					itemlist+= items[i].id.substr(3)+",";
				}
				$.ajax({
					type: "POST",
				   	dataType: "json",
				   	url: "/admin-mvc/news/manage/delete",
				   	data: "items="+itemlist,
				   	success: function(data){
				   		alert(data.total + " News Deleted");
				   		$("#flex1").flexReload();
			   	    }
				});
			}
		} else {
			alert('Please select at least 1 News');
		} 
	}
	 else if (com=='Add'){
	 
		AddContent('/admin-mvc/news/manage/add','Add News');
	}else if(com=='Edit'){
	       if($('.trSelected',grid).length>0 && $('.trSelected',grid).length<=1 ){
	   		
            	var items = $('.trSelected',grid);
            	var itemlist ='';
        		itemlist+= items[0].id.substr(3);
				
				AddContent('/admin-mvc/news/manage/add/'+itemlist);
				
		} else if($('.trSelected',grid).length==0){
			alert('Please select a Content');
		} else {
			alert('Please select Only 1 News');
		}
			
	}
	
	
}
function AddContent(linkUrl,title)
{
	
	//tb_show(title,linkUrl,null);
	window.location = linkUrl;
	
}

//]]>
</script>
<div id="content_body">

	<div class="clear"></div><br/>
<table id="flex1" style="display:none;"></table><br/>
<div class="clear"></div>

</div>
<div class="clear"></div>

